<?php

namespace App\Jobs\Zhunya;

use App\Models\CacheModel\OrdersLib as OrdersLibCacheModel;
use App\Models\CacheModel\ZlVipBoon;
use Cache;
use Log;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class VipTask implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $jobData;

    /**
     * Create a new job instance.
     *
     * @param array $jobData
     */
    public function __construct(array $jobData)
    {
        $this->jobData = $jobData;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function starNumUpdateAndSendBoon()
    {
      $jobData = $this->jobData;
      Log::write(date('Y-m-d h:i:s') . ':星力值更新及权益赠送开始：' . json_encode($jobData), 'log');
        if ($job->attempts() > 1)
        {
            $job->delete();
        }
        
        // 更新星力值
        OrdersLibCacheModel::UpdateVipBoon($jobData['orders'], $jobData['gid'], $jobData['isUpdateVipSendBoon']);
        // 激活会员或开通会员赠送权益
        if ($jobData['isSend'])
        {
            (new ZlVipBoon())->vipBoonSend($jobData['orders']['uid']);
        }

        $job->delete();
        Log::write(date('Y-m-d h:i:s') . ':星力值更新及权益赠送结束：' . json_encode($jobData), 'log');
    }
}